// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'


import App from './App.vue'

// -------------------引入路由----------------------------
import VueRouter from 'vue-router'
Vue.use(VueRouter)
import router from './router/router.js'
// -------------------引入AJAX----------------------------

import VueResource from 'vue-resource'
Vue.use(VueResource)
// -------------------引入AJAX----------------------------

import VueLazyload from 'vue-lazyload'
Vue.use(VueLazyload,{
  loading:'/static/loading/loading-balls.svg'
})


// -------------------引入滚动分页插件-----------------------------
import infiniteScroll from 'vue-infinite-scroll'
Vue.use(infiniteScroll)

// -------------------引入金额过滤器-----------------------------

import { currency } from './util/currency'

Vue.filter('currency',currency)
  
//---------------------引入VUEX----------------------------------------
import Vuex from 'vuex'
Vue.use(Vuex)

// -------------------引入CSS----------------------------
import './css/base.css'
import  './css/product.css'
import './css/checkout.css'
import './css/login.css'

var localcar = JSON.parse(localStorage.getItem('car') || '[]')
const store = new Vuex.Store({
  state: {
    car:localcar
  },
  mutations: {
    increment(state,pathinfo) {
      state.car=pathinfo
      var strcar = JSON.stringify(state.car)
      localStorage.setItem('car',strcar)
    },
    add(state,pathinid){
      state.car.forEach(item=>{
        if(item.productId==pathinid){
          item.productNum++
        }
      })
    }
    
  },
  getters: {
    getsmall(state){
      var count = 0
      state.car.forEach(item=>{
        if(item.checked==1){
           count += parseInt(item.productNum)
        }
      })
      return count
    }
  }
})




Vue.config.productionTip = false


var vm = new Vue({
  el: '#app',
  router,
  render:c => c(App),
  store
})
